//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.Blackboard.Wcf
{
    using System;
    using Microsoft.Research.eResearch.Blackboard.Common;
    using Microsoft.Research.eResearch.Blackboard.Interfaces;
    using Microsoft.Research.eResearch.Blackboard.Wcf.WcfPublisherSubscriptionService;

    /// <summary>
    /// Provides a WCF implementation of the IPublisherSubscriptionSender interface.
    /// This implementation allows the Blackboard to send a new subscription profile 
    /// to a publisher.
    /// </summary>
    public class WcfPublisherSubscriptionClient : IPublisherSubscriptionSender
    {
        /// <summary>
        /// Notifies the publisher at the specified address of updates in
        /// the subscription profile.
        /// </summary>
        /// <param name="address">The address of the publisher.</param>
        /// <param name="profile">The new subscription profile.</param>
        public void UpdateSubscriptionProfile(Uri address, SubscriptionProfile profile)
        {
            WcfPublisherSubscriptionServiceClient client =
                new WcfPublisherSubscriptionServiceClient(
                    "WcfPublisherSubscriptionClient", // the endpoint configuration to load from the App.config file
                    address.ToString());
            client.Open();
            client.UpdateSubscriptionProfile(profile.ToArray());
            client.Close();
        }
    }
}
